package com.trust.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.trust.agri.response.ResponseResult;
import com.trust.agri.sign.validate.SaveValidate;
import com.trust.annotation.SYQLog;
import com.trust.entity.DTO.PurchaseDTO;
import com.trust.entity.Param.PurchaseListParam;
import com.trust.entity.Purchase;
import com.trust.entity.VO.PurchaseVO;
import com.trust.service.PurchaseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Slf4j
@RequestMapping("/api/purchase")
@Api(value = "订单管理 - 采购单", tags = "订单管理 - 采购单")
public class PurchaseController {

    @Resource
    private PurchaseService service;

    @PostMapping("/list")
    @ApiOperation("采购单列表")
    public ResponseResult<Page<PurchaseVO>> list(@RequestBody PurchaseListParam param){
        Page<PurchaseVO> page = service.list(param);
        return ResponseResult.ok(page);
    }

    @PostMapping("/save")
    @ApiOperation("新增采购单")
    @SYQLog(type = "新增采购单", name = "采购单")
    public ResponseResult<Purchase> save(@Validated(SaveValidate.class) @RequestBody PurchaseDTO param){
        Purchase purchase = service.saveAndUpdate(param);
        return ResponseResult.ok(purchase);
    }
}
